package com.wkhyapp.lm.view;

import android.os.Build;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.base.SuperActivity;
import com.wkhyapp.lm.constant.Constant;
import com.wkhyapp.lm.contract.NoticePresenter;
import com.wkhyapp.lm.contract.NoticeView;
import com.wkhyapp.lm.http.vo.Notice;
import com.wkhyapp.lm.utils.StatusBarFontUtil;

import java.util.List;

import butterknife.BindView;

public class LoginActivity extends SuperActivity<NoticePresenter>  implements NoticeView{


    @BindView(R.id.login_rl)
    RelativeLayout login_rl;
    private IWXAPI api = null;
    SendAuth.Req req = new SendAuth.Req();
    public static LoginActivity loginActivity;
    @BindView(R.id.login_cb)
    CheckBox login_cb;
    @BindView(R.id.yhxy_tv)
    TextView yhxy_tv;
    @BindView(R.id.yscl_tv)
    TextView yscl_tv;
    @BindView(R.id.phone_rl)
    RelativeLayout phone_rl;
    @BindView(R.id.tips_iv)
    TextView tips_iv;
    @BindView(R.id.login_iv)
    ImageView login_iv;
    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            translucentStatusBar();
        }
        StatusBarFontUtil.setLightStatusBarColor(this);
        api = WXAPIFactory.createWXAPI(mContext, Constant.APP_ID);
        api.registerApp(Constant.APP_ID);
        loginActivity = this;
    }

    @Override
    protected void initListener() {
        login_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(!login_cb.isChecked()){
                    VISIBLE(tips_iv);
                    return;
                }

                if(api.isWXAppInstalled()){
                    showLoad("正在加载...");
                    req.scope = "snsapi_userinfo";
                    req.state = "wechat_login";
                    api.sendReq(req);

                }else{
                    TToast("请先安装微信~");
                }
            }
        });


        login_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!login_cb.isChecked()){
                    VISIBLE(tips_iv);
                    return;
                }

                if(api.isWXAppInstalled()){
                    showLoad("正在加载...");
                    req.scope = "snsapi_userinfo";
                    req.state = "wechat_login";
                    api.sendReq(req);

                }else{
                    TToast("请先安装微信~");
                }
            }
        });

        yhxy_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTo(WebViewActivity.class,"http://img.wkhyw.com/yhxy.html","用户协议");
            }
        });

        yscl_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTo(WebViewActivity.class,"http://img.wkhyw.com/yssm.html","隐私声明");
            }
        });

        phone_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!login_cb.isChecked()){
                    VISIBLE(tips_iv);
                    return;
                }

                goTo(PhoneLoginActivity.class);
                finish();
            }
        });

        login_cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    GONE(tips_iv);
                }
            }
        });

    }


    @Override
    protected void afterCreate() {

    }


    @Override
    protected NoticePresenter createPresenter() {
        return mPresenter = new NoticePresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void setNotice(List<Notice> list) {

    }

    @Override
    public void setNoticeMore(List<Notice> list) {

    }


}
